package com.price.common.util

import android.R
import android.app.Activity
import android.view.View
import com.google.android.material.snackbar.Snackbar

/**
 * 替换Toast
 */
object SnackBarUtils {
    fun showLong(activity: Activity, msg: String) {
        Snackbar.make(
            activity.findViewById(R.id.content), msg,
            Snackbar.LENGTH_LONG
        )
            .show()
    }

    fun show(activity: Activity, msg: String) {
        Snackbar.make(
            activity.findViewById(R.id.content), msg,
            Snackbar.LENGTH_SHORT
        )
            .show()
    }

    fun show(
        activity: Activity,
        msg: String,
        action: String?,
        onClickListener: View.OnClickListener?
    ) {
        Snackbar.make(
            activity.findViewById(R.id.content), msg,
            Snackbar.LENGTH_INDEFINITE
        )
            .setAction(action, onClickListener)
            .show()
    }

    fun show(activity: Activity, msg: Int, action: Int, onClickListener: View.OnClickListener?) {
        Snackbar.make(
            activity.findViewById(R.id.content), msg,
            Snackbar.LENGTH_INDEFINITE
        )
            .setAction(action, onClickListener)
            .show()
    }

    /**
     * @param duration Snackbar.LENGTH_INDEFINITE -2,Snackbar.LENGTH_SHORT -1,Snackbar.LENGTH_LONG 0,
     */
    fun show(activity: Activity, msg: String, duration: Int) {
        Snackbar.make(
            activity.findViewById(R.id.content), msg,
            duration
        )
            .show()
    }

    /**
     * @param duration Snackbar.LENGTH_INDEFINITE -2,Snackbar.LENGTH_SHORT -1,Snackbar.LENGTH_LONG 0,
     */
    fun show(activity: Activity, msgId: Int, duration: Int) {
        Snackbar.make(
            activity.findViewById(R.id.content), msgId,
            duration
        )
            .show()
    }

    /**
     * @param duration Snackbar.LENGTH_INDEFINITE -2,Snackbar.LENGTH_SHORT -1,Snackbar.LENGTH_LONG 0,
     */
    fun show(
        activity: Activity,
        msg: String,
        duration: Int,
        action: String?,
        onClickListener: View.OnClickListener?
    ) {
        Snackbar.make(
            activity.findViewById(R.id.content), msg,
            duration
        )
            .setAction(action, onClickListener)
            .show()
    }

    /**
     * @param duration Snackbar.LENGTH_INDEFINITE -2,Snackbar.LENGTH_SHORT -1,Snackbar.LENGTH_LONG 0,
     */
    fun show(
        activity: Activity,
        msgId: Int,
        duration: Int,
        actionId: Int,
        onClickListener: View.OnClickListener?
    ) {
        Snackbar.make(
            activity.findViewById(R.id.content), msgId,
            duration
        )
            .setAction(actionId, onClickListener)
            .show()
    }
}
